package com.example.springaiollamademodemo;// src/main/java/com/example/springaiollamademodemo/SpringAiOllamaDemoApplication.java


import org.junit.jupiter.api.Test;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
public class SpringAiOllamaDemoApplicationTests {

    @Autowired
    private ChatClient chatClient;

    /**
     * 测试 ChatClient 是否能正常调用大模型并返回响应内容
     */
    @Test
    void testChatClientReturnsResponseContent() {
        String response = chatClient.prompt()
                .user("解释下量子纠缠的原理")
                .call()
                .content();

        // 验证返回内容是否非空
        assertThat(response).isNotBlank();

        // 可选：根据实际返回内容添加关键词断言（例如“量子态”、“超距作用”等）
        System.out.println("大模型响应: " + response);
    }

    /**
     * 测试 ChatClient 是否能处理多轮对话中的上下文记忆
     */
    @Test
    void testChatClientWithMemory() {
        String firstResponse = chatClient.prompt()
                .user("中国的首都是哪里？")
                .call()
                .content();

        String followUpResponse = chatClient.prompt()
                .user("它的简称是什么？")
                .call()
                .content();

        // 简单验证两次响应都非空
        assertThat(firstResponse).isNotBlank();
        assertThat(followUpResponse).isNotBlank();

        System.out.println("首次提问响应: " + firstResponse);
        System.out.println("后续提问响应: " + followUpResponse);
    }
}
